package com.globallogic.vacationplanner.model.dao.impl;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Repository;

import com.globallogic.vacationplanner.model.dao.declaration.IUserDao;
import com.globallogic.vacationplanner.model.entity.User;

@Repository("userDao")
public class UserDao extends BaseDao<User> implements IUserDao {
	private static final long serialVersionUID = 1L;
	private static Logger LOGGER = Logger.getLogger(UserDao.class);

	public UserDao() {
		super();
		LOGGER.info("UserDao has been created");
	}

	@Override
	String getReadAllQuery() {
		return "from User";
	}

	/**
	 * {@inheritDoc}
	 */
	@SuppressWarnings("unchecked")
	@Override
	public boolean findUserByLogin(String login) {
		LOGGER.info("find user by login: " + login);
		List<User> users = getHibernateTemplate().findByNamedParam(
				"from User where login = :login", "login", login);

		LOGGER.info("user had been find");
		LOGGER.info("user is empty: " + users.isEmpty());
		return users.isEmpty();
	}
}
